<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
    <title>x小区管理</title>
    <meta name="decorator" content="default"/>
    <script>
        var isok=1;
        $(function(){
            $("#cname").blur(function(){
                var oldCommName=$("#oname").val();
                var commName=$("#cname").val();
                var aes=$("#areaId").val();
                if(aes=="请选择"){
                    var tt=document.getElementById("tt");
                    tt.innerHTML="请选择区域名称";
                }else{
                    $.ajax({
                        type : "POST",
                        url : "${ctx}/sys/community/agentCheckCommName",
                        data : {
                            oldCommName : oldCommName,
                            commName:commName,
                            aes:aes
                        },
                        success : function(data) {
                            if(data=="false"){
                                document.getElementById("nn").innerHTML="该小区名称已经存在！";
                                isok=2;
                            }else{
                                document.getElementById("nn").innerHTML="*";
                                isok=1;
                            }
                        }
                    });
                }

            });
        });

    </script>
    <script type="text/javascript">

        $(document).ready(function() {
            $("#box").focus();
            $("#inputForm").validate({
                rules:{
                 //   commName: {remote: "${ctx}/sys/community/checkCommName?oldCommName=" + encodeURIComponent('${tbCommunity.commName}')},
                    areaId:{
                        required:true,
                        areaId:"areaId"
                    }
                },
             /*  messages: {
                    commName: {remote: "该小区名称已存在"}
                },*/
                submitHandler: function(form){
                    loading('正在提交，请稍等...');
                    form.submit();
                },
                errorContainer: "#messageBox",
                errorPlacement: function(error, element) {
                    $("#messageBox").text("输入有误，请先更正。");
                    if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
                        error.appendTo(element.parent().parent());
                    } else {
                        error.insertAfter(element);
                    }
                }
            });
            $.validator.addMethod("areaId",function(values,elements){
                if(values=="请选择"){
                    var tt=document.getElementById("tt");
                    tt.innerHTML="请选择区域名称";
                    return false;
                }else if(isok==2){
                    document.getElementById("nn").innerHTML="该小区名称已经存在！";
                    return false;
                }else{
                    var tt=document.getElementById("tt");
                    tt.innerHTML="*";
                    return true;
                }
            },"");
            $("#areaId").change(function(){
                var tt=document.getElementById("tt");
                tt.innerHTML="*";
            });
        });
    </script>
</head>
<body>
<ul class="nav nav-tabs">
    <li class="active"><a href="#">小区信息</a></li>
</ul><br/>
<form:form id="inputForm" modelAttribute="tbCommunity" action="${ctx}/sys/community/communityEdit" method="post" class="form-horizontal">
    <form:hidden path="id"/>
    <sys:message content="${message}"/>
    <div class="control-group">
        <label class="control-label">省:</label>
        <div class="controls">
            <label class="lbl">${tbCommunity.provinceName}</label>
        </div>
    </div>
    <div class="control-group">
        <label class="control-label">市:</label>
        <div class="controls">
            <label class="lbl">${tbCommunity.cityName}</label>
        </div>
    </div>
    <div class="control-group">
        <label class="control-label">区:</label>
        <div class="controls">
            <label class="lbl">${tbCommunity.areaName}</label>
        </div>
    </div>
    <div class="control-group">
        <label class="control-label">小区名称:</label>
        <div class="controls">
            <label class="lbl">${tbCommunity.commName}</label>
        </div>
    </div>
    <div class="control-group">
        <label class="control-label">详细地址:</label>
        <div class="controls">
            <label class="lbl"> ${tbCommunity.address}</label>
        </div>
    </div>

    <div class="control-group">
        <label class="control-label">是否显示:</label>
            <c:if test="${tbCommunity.isActive==0}">
                <div class="controls">
                    <label class="lbl">否</label>
                </div>
            </c:if>
            <c:if test="${tbCommunity.isActive==1}">
                <div class="controls">
                    <label class="lbl">是</label>
                </div>
            </c:if>
    </div>

    <div class="form-actions">
        <input id="btnCancel" class="btn" type="button" value="返 回" onclick="history.go(-1)"/>
    </div>
</form:form>
</body>
</html>